<script setup>
import { ref } from 'vue'
const article = ref(
  {
    id: '1',
    title: 'React Hooks 入门指南',
    description: '全面了解 React Hooks 及其实际应用的完整指南',

    category: '编程',
    tags: ['React', 'JavaScript', 'Web开发'],
    author: {
      id: 'author1',
      name: '陈小华',
      avatar:
        'https://images.unsplash.com/photo-1494790108377-be9c29b29330?w=400',
      bio: '拥有8年经验的高级前端开发工程师',
      expertise: ['React', 'TypeScript', '前端架构']
    },
    publishedDate: '2024-03-15',
    readTime: 8,
    imageUrl:
      'https://images.unsplash.com/photo-1633356122544-f134324a6cee?w=800'
  },
  {
    id: '2',
    title: '开发者必备的UI设计原则',
    description: '每个开发者都应该了解的基本设计原则',

    category: '设计',
    tags: ['UI设计', '用户体验', 'Web开发'],
    author: {
      id: 'author2',
      name: '李明',
      avatar:
        'https://images.unsplash.com/photo-1472099645785-5658abf4ff4e?w=400',
      bio: 'UI/UX设计师和前端开发工程师',
      expertise: ['UI设计', '用户体验', '前端开发']
    },
    publishedDate: '2024-03-14',
    readTime: 6,
    imageUrl: 'https://images.unsplash.com/photo-1545235617-9465d2a55698?w=800'
  }
)
</script>
<template>
  <div class="train-card" @click="handleClick">
    <img
      :src="article.imageUrl"
      :alt="article.title"
      class="train-card__image"
    />
    <div class="train-card__content">
      <div class="train-card__header">
        <span class="train-card__category">
          {{ article.category }}
        </span>
        <div class="train-card__read-time">
          <img src="@/assets/icon/clock.png" />
          <span class="train-card__read-time-text">
            {{ article.readTime }}分钟前发布</span
          >
        </div>
      </div>
      <h3 class="train-card__title">{{ article.title }}</h3>
      <p class="train-card__description">{{ article.description }}</p>
      <div class="train-card__footer">
        <div class="train-card__author">
          <img
            :src="article.author.avatar"
            :alt="article.author.name"
            class="train-card__author-avatar"
          />
          <span class="train-card__author-name">{{ article.author.name }}</span>
        </div>
        <div class="train-card__tag">
          <img src="@/assets/icon/tag.png" />
          <span class="train-card__tag-text">{{ article.tags[0] }}</span>
        </div>
      </div>
    </div>
  </div>
</template>
<style lang="scss" scoped>
.train-card {
  width: 40%;
  background-color: white;
  border-radius: 0.5rem;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s ease-in-out;

  &:hover {
    transform: scale(1.02);
  }

  &__image {
    width: 100%;
    height: 12rem;
    object-fit: cover;
  }

  &__content {
    padding: 1.5rem;
  }

  &__header {
    display: flex;
    align-items: center;
    margin-bottom: 0.5rem;

    .train-card__category {
      background-color: #ebf8ff;
      color: #2b6cb0;
      font-size: 0.75rem;
      font-weight: 600;
      padding: 0.25rem 0.5rem;
      border-radius: 0.375rem;
      margin-right: 0.5rem;
    }

    .train-card__read-time {
      display: flex;
      align-items: center;
      color: #6b7280;
      font-size: 0.875rem;

      .train-card__read-time-text {
        margin-left: 0.25rem;
      }
    }
  }

  &__title {
    font-size: 1.25rem;
    font-weight: bold;
    margin-bottom: 0.5rem;
    color: #111827;
  }

  &__description {
    color: #4b5563;
    margin-bottom: 1rem;
  }

  &__footer {
    display: flex;
    justify-content: space-between;
  }

  &__author {
    display: flex;
    align-items: center;

    .train-card__author-avatar {
      width: 2rem;
      height: 2rem;
      border-radius: 50%;
      margin-right: 0.75rem;
    }

    .train-card__author-name {
      font-size: 0.875rem;
      font-weight: 500;
      color: #111827;
    }
  }

  &__tag {
    display: flex;
    align-items: center;

    image {
      width: 0.7rem;
      height: 0.7rem;
    }
    .train-card__icon {
      width: 1rem;
      height: 1rem;
      margin-right: 0.25rem;
      color: #6b7280;
    }

    .train-card__tag-text {
      font-size: 1rem;
      margin-left: 0.4rem;
      color: #6b7280;
    }
  }
}
</style>
